<template>
  <el-dialog
    :title="!dataForm.id ? $t('Common.Add') : $t('Common.Edit')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="商家" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="商家"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="creatTime">
      <el-input v-model="dataForm.creatTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="身份类型（0居民身份证1户口簿2军官证3警官证4士兵证5护照6其他）" prop="type">
      <el-input v-model="dataForm.type" placeholder="身份类型（0居民身份证1户口簿2军官证3警官证4士兵证5护照6其他）"></el-input>
    </el-form-item>
    <el-form-item label="姓名" prop="name">
      <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="tel">
      <el-input v-model="dataForm.tel" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="证件号" prop="certificatesNumber">
      <el-input v-model="dataForm.certificatesNumber" placeholder="证件号"></el-input>
    </el-form-item>
    <el-form-item label="房间id" prop="floorRoomId">
      <el-input v-model="dataForm.floorRoomId" placeholder="房间id"></el-input>
    </el-form-item>
    <el-form-item label="预抵时间" prop="arrivalsTime">
      <el-input v-model="dataForm.arrivalsTime" placeholder="预抵时间"></el-input>
    </el-form-item>
    <el-form-item label="预离时间" prop="predissociationTime">
      <el-input v-model="dataForm.predissociationTime" placeholder="预离时间"></el-input>
    </el-form-item>
    <el-form-item label="已付款" prop="payment">
      <el-input v-model="dataForm.payment" placeholder="已付款"></el-input>
    </el-form-item>
    <el-form-item label="房价" prop="roomPrice">
      <el-input v-model="dataForm.roomPrice" placeholder="房价"></el-input>
    </el-form-item>
    <el-form-item label="已消费" prop="consumption">
      <el-input v-model="dataForm.consumption" placeholder="已消费"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          creatTime: '',
          type: '',
          name: '',
          tel: '',
          certificatesNumber: '',
          floorRoomId: '',
          arrivalsTime: '',
          predissociationTime: '',
          payment: '',
          roomPrice: '',
          consumption: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家不能为空', trigger: 'blur' }
          ],
          creatTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '身份类型（0居民身份证1户口簿2军官证3警官证4士兵证5护照6其他）不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '手机号不能为空', trigger: 'blur' }
          ],
          certificatesNumber: [
            { required: true, message: '证件号不能为空', trigger: 'blur' }
          ],
          floorRoomId: [
            { required: true, message: '房间id不能为空', trigger: 'blur' }
          ],
          arrivalsTime: [
            { required: true, message: '预抵时间不能为空', trigger: 'blur' }
          ],
          predissociationTime: [
            { required: true, message: '预离时间不能为空', trigger: 'blur' }
          ],
          payment: [
            { required: true, message: '已付款不能为空', trigger: 'blur' }
          ],
          roomPrice: [
            { required: true, message: '房价不能为空', trigger: 'blur' }
          ],
          consumption: [
            { required: true, message: '已消费不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinpeople/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tHotelFloorRoomCheckinPeople.sellerId
                this.dataForm.creatTime = data.tHotelFloorRoomCheckinPeople.creatTime
                this.dataForm.type = data.tHotelFloorRoomCheckinPeople.type
                this.dataForm.name = data.tHotelFloorRoomCheckinPeople.name
                this.dataForm.tel = data.tHotelFloorRoomCheckinPeople.tel
                this.dataForm.certificatesNumber = data.tHotelFloorRoomCheckinPeople.certificatesNumber
                this.dataForm.floorRoomId = data.tHotelFloorRoomCheckinPeople.floorRoomId
                this.dataForm.arrivalsTime = data.tHotelFloorRoomCheckinPeople.arrivalsTime
                this.dataForm.predissociationTime = data.tHotelFloorRoomCheckinPeople.predissociationTime
                this.dataForm.payment = data.tHotelFloorRoomCheckinPeople.payment
                this.dataForm.roomPrice = data.tHotelFloorRoomCheckinPeople.roomPrice
                this.dataForm.consumption = data.tHotelFloorRoomCheckinPeople.consumption
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinpeople/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'creatTime': this.dataForm.creatTime,
                'type': this.dataForm.type,
                'name': this.dataForm.name,
                'tel': this.dataForm.tel,
                'certificatesNumber': this.dataForm.certificatesNumber,
                'floorRoomId': this.dataForm.floorRoomId,
                'arrivalsTime': this.dataForm.arrivalsTime,
                'predissociationTime': this.dataForm.predissociationTime,
                'payment': this.dataForm.payment,
                'roomPrice': this.dataForm.roomPrice,
                'consumption': this.dataForm.consumption
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
